﻿using System;

namespace Little.Soldier.SWIFT.Definition
{
  [Serializable]
  internal class SwiftTagSubItemDefinition : SwiftDefinitionElement
  {
    public SwiftTagSubItemDefinition()
    {
    }

    public SwiftTagSubItemDefinition(string name, string description)
      : base(name, description)
    {
    }

    public override void U008E(SwiftDefinitionElement element)
    {
      if (!(element is SwiftTagSubItemDefinition))
        throw new InvalidOperationException("SwiftTagSubItem can only contain SwiftTagSubItem elements");
      base.U008E(element);
    }

    public override bool U008F(object obj)
    {
      SwiftTagSubItemDefinition subItemDefinition = obj as SwiftTagSubItemDefinition;
      if (subItemDefinition == null || !(this.Name.ToLower().Replace("and", "").Replace("_", "") == subItemDefinition.Name.ToLower().Replace("and", "").Replace("_", "")))
        return false;
      else
        return this.Elements.Count == subItemDefinition.Elements.Count;
    }
  }
}
